$(function () {
    $("#tou").load("tou.html");
//加载订单详情
    orderDetails();
});

//加载订单详情
function orderDetails() {
        var orderId = getQueryString("orderId");
        $.ajax({
            url:"easybuy/orderdetails",
            data:{
                orderId:orderId
            },
            success:function (data) {
                var orderDetails = data[0];
                var products = data[1];
                var order = data[2];
                var user = data[3];
                $(".orderDetail_tab").append("" +
                    "                <tr style=\"background-color: #d1d0d1\">\n" +
                    "                    <td width=\"25%\">用户名："+order.loginname+"</td>\n" +
                    "                    <td width=\"25%\">订单号："+order.serialnumber+"</td>\n" +
                    "                    <td width=\"20%\">总付款：￥"+order.cost+"</td>\n" +
                    "                    <td width=\"30%\">地址："+order.useraddress+"</td>\n" +
                    "                </tr>\n" +
                    "                <tr style='height: 50px'>\n" +
                    "                    <td width=\"25%\">商品名</td>\n" +
                    "                    <td width=\"25%\">商品图片</td>\n" +
                    "                    <td width=\"20%\">数量</td>\n" +
                    "                    <td width=\"30%\">单价</td>\n" +
                    "                </tr>");
                $.each(orderDetails,function (index,orderDetail) {
                    var product = products[index];
                    $(".orderDetail_tab").append(
                        "                <tr style='border-top: 1px solid #d1d0d1' data-id="+product.id+">\n" +
                        "                    <td width=\"25%\">"+product.name+"</td>\n" +
                        "                    <td width=\"25%\"><a href='Product.html?id="+product.id+"'><img src='http://47.104.137.246:9999/files/"+product.filename+"' alt='' style='height: 50px'></a></td>\n" +
                        "                    <td width=\"20%\">"+orderDetail.quantity+"</td>\n" +
                        "                    <td width=\"30%\">￥"+orderDetail.cost+"</td>\n" +
                        "                </tr>");
                })
            }
        });
}

//取得地址栏参数
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg); //r是一个数组
    if (r != null) return unescape(r[2]); return null;}